// 短信验证码登录

import pkRequest from '@/service'
import type {
  IAllUserPatient,
  ICertificatesType,
  IGetCodeByPhone,
  ILoginData,
  ILoginResponseData,
  IUserInfo,
  IUserParams
} from './type'

enum API_USER {
  SMS_GET_CODE_BY_PHONE = '/api/sms/send',
  LOGIN_BY_PHONE_CODE = '/api/user/login',
  USER_PATIENT_ALL = '/api/user/patient/auth/findAll',
  GET_USERINFO = '/api/user/auth/getUserInfo',
  CERTIFICATES_TYPE = '/api/cmn/dict/findByDictCode',
  USER_CERTATION = '/api/user/auth/userAuah'
}

export const reqGetCodeByPhone = (phone: string) =>
  pkRequest.get<IGetCodeByPhone>({
    url: API_USER.SMS_GET_CODE_BY_PHONE + `/${phone}`
  })

export const postLoginByPhoneAndCode = (data: ILoginData) =>
  pkRequest.post<ILoginResponseData>({
    url: API_USER.LOGIN_BY_PHONE_CODE,
    data
  })

export const reqGetUserPatientAll = () =>
  pkRequest.get<IAllUserPatient>({
    url: API_USER.USER_PATIENT_ALL
  })
// 获取会员登录信息
export const reqGetUserInfo = () =>
  pkRequest.get<IUserInfo>({
    url: API_USER.GET_USERINFO
  })
// 获取证件类型
export const reqCertificatesType = (dictCode = 'certificatesType') =>
  pkRequest.get<ICertificatesType>({
    url: API_USER.CERTIFICATES_TYPE + `/${dictCode}`
  })
// 用户实名认证
export const postUserCertation = (config: IUserParams) => {
  return pkRequest.post<any>({
    url: API_USER.USER_CERTATION,
    data: { ...config }
  })
}
